<?php
require_once 'DBConnecter.inc';
class MonthlyReport extends DBConnecter {
	public $mem_id = ""; // 사원번호          
	public $name = ""; // 성명              
	public $account_fee = ""; // 기장료            
	public $acct_fee = ""; // 사고접보비        
	public $act_nm = ""; // 예금주명          
	public $actno = ""; // 계좌번호          
	public $ada_pay = ""; // 선지급            
	public $annual_pay = ""; // 연차수당          
	public $apd_dil_exp = ""; // 운송료추가        
	public $attend_deduct_amt = ""; // 지각/조퇴/결근공제
	public $attend_exp = ""; // 만근지원비        
	public $bank_nm = ""; // 지급은행          
	public $c_brno = ""; // 근무점포          
	public $car_assist_amt = ""; // 차량보조          
	public $car_id = ""; // 차량번호          
	public $car_no = ""; // 차량번호등록판    
	public $car_tax = ""; // 자동차세          
	public $car_wash_exp = ""; // 세차비            
	public $charoff_etc_fee = ""; // 기타              
	public $city_tax = ""; // 주민세            
	public $closing_date = ""; // 결산일            
	public $comm_exp = ""; // 통신비            
	public $commit_fee = ""; // 환경개선비/협회비 
	public $commit_pay = ""; // 교통비            
	public $commute_oil_fee = ""; // 출퇴근유류비      
	public $cusm_cd = ""; // 거래처            
	public $dayoff_dedt = ""; // 휴무공제          
	public $deposit = ""; // 예치금            
	public $dil_etc_exp = ""; // 기타              
	public $dil_van_exp = ""; // 용차비            
	public $dispatcher_amt = ""; // 디스패쳐          
	public $early_slot = ""; // EARLY SLOT        
	public $etc_amt = ""; // 기타경비          
	public $etc_deduct_amt = ""; // 기타공제          
	public $etc_pay = ""; // 기타수당          
	public $ex_incen_pay = ""; // 인센티브          
	public $extension_pay = ""; // 연장수당          
	public $fare_amt = ""; // 기본 운송료       
	public $fine_fee = ""; // 과태료            
	public $gps_fee = ""; // GPS               
	public $incen_pay = ""; // 운행장려금        
	public $incm_tax = ""; // 사업소득세        
	public $income_tax = ""; // 갑근세            
	public $instl_deg = ""; // 할부회차          
	public $instl_fee = ""; // 차량할부          
	public $insu_deg = ""; // 회차              
	public $insu_fee = ""; // 보험료            
	public $insurance_fee = ""; // 건강보험          
	public $meal_pay = ""; // 식대비            
	public $mileage_fee = ""; // 유류연비차액      
	public $mngt_exp = ""; // 관리비            
// 	public $name = ""; // 성명              
	public $oil_exp = ""; // 유류비            
	public $paint_exp = ""; // 도색비            
	public $pension_fee = ""; // 국민연금          
	public $per_incen_pay = ""; // 건당인센티브          
	public $prepay_amt = ""; // 선급금            
	public $receipt_exp = ""; // 기타2             
	public $recuperation_fee = ""; // 장기요양          
	public $soyu_tp = ""; // 기사구분          
	public $sply_amt = ""; // 지급액            
	public $sply_dt = ""; // 지급일            
	public $surtax = ""; // 부가세            
	public $trans_fee = ""; // 이체수수료        
	public $unemploy_insurance_fee = ""; // 고용보험      
	public $gubun_tp = "";
	public $attend_cnt = "";
	public $dayoff_cnt = "";
// 	public $soyu_tp = "";
	public $notice = "";
	
	function __construct() {
		$this->connectDB ();
		// $this->selectDB ( 'devdog' );
	}
	public function tablePrint() {
		echo "<tr onclick=\"location.href='./monthly_report.php?id=" . $this->mem_id . "&time=".$this->closing_date."'\">";
		
		echo "<td>" . $this->work_time . "</td>";
		echo "<td>" . $this->mem_id . "</td>";
		echo "<td>" . $this->name . "</td>";
		echo "<td>" . $this->soyu_tp . "</td>";
		echo "<td>" . Number_Format ( $this->tot_dil_amt ) . "</td>";
		echo "<td>" . Number_Format ( $this->tot_dedt_amt ) . "</td>";
		echo "<td>" . Number_Format ( $this->sply_amt ) . "</td>";
		echo "<td>" . $this->closing_date . "</td>";
		echo "<td>" . $this->sply_yn . "</td>";
		echo "<td>" . $this->bank_nm . "</td>";
		echo "<td>" . $this->act_nm . "</td>";
		echo "<td>" . $this->actno . "</td>";
		
		echo "</tr>";
	}
	public function search4table($table, $fr_dt, $to_dt, $category, $value) {
		$sql = "CALL ".self::CONST_DB.".monthly_search('1','" . $fr_dt . "','" . $to_dt . "','" . $category . "','" . $value . "');select @out_err_cd, @out_err_msg;";
		$retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
// 					$this->car_id = $row ['0'];
					
					$this->work_time = $row ['0'];
					$this->mem_id = $row ['1'];
					$this->name = $row ['2'];
					$this->soyu_tp = $row ['3'];
					$this->tot_dil_amt = $row ['4'];
					$this->tot_dedt_amt = $row ['5'];
					$this->sply_amt = $row ['6'];
					$this->closing_date = $row ['7'];
					$this->sply_yn = $row ['8'];
					$this->bank_nm = $row ['9'];
					$this->act_nm = $row ['10'];
					$this->actno = $row ['11'];
					$this->c_brno = $row ['12'];
					
					$this->tablePrint ();
				}
				$rs->free ();
			}
		}
	}
	public function search4Detail($value, $time) {
		$sql = "CALL ".self::CONST_DB.".pay_clac_search('" . $value . "','" . $time . "');select @out_err_cd, @out_err_msg;";
		$retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					/*
					$this->mem_id = $row ['0']; // 사원번호
					$this->name = $row ['1']; // 이름
					$this->cusm_cd = $row ['2']; // 거래처코드
					$this->c_brno = $row ['3']; // 차량소속
					$this->car_id = $row ['4']; // 차량번호
					$this->soyu_tp = $row ['5']; // 소유구분 
					$this->bank_nm = $row ['6']; // 거래은행명
					$this->act_nm = $row ['7']; // 예금주
					$this->actno = $row ['8']; // 계좌번호
					$this->sply_amt = $row ['9']; // 실지급액
					$this->fare_amt = $row ['10']; // 기본운송료
					$this->comm_exp = $row ['11']; // 통신비
					$this->car_wash_exp = $row ['12']; // 세차비
					$this->attend_exp = $row ['13']; // 만근지원비
					$this->incen_pay = $row ['14']; // 운행장려금2
					$this->dil_van_exp = $row ['15']; // 용차비
					$this->apd_dil_exp = $row ['16']; // 운송료추가
					$this->dil_etc_exp = $row ['17']; // 기타
					$this->receipt_exp = $row ['18']; // 기타2(영수증)
					$this->mngt_exp = $row ['19']; // 관리비
					$this->surtax = $row ['20']; // 부가세
					$this->insu_fee = $row ['21']; // 보험료
					$this->insu_deg = $row ['22']; // 보험료회차
					$this->commit_fee = $row ['23']; // 환경개선비_협회비
					$this->car_tax = $row ['24']; // 자동차세
					$this->gps_fee = $row ['25']; // GPS 비용
					$this->fine_fee = $row ['26']; // 과태료
					$this->acct_fee = $row ['27']; // 사고접부비
					$this->mileage_fee = $row ['28']; // 유류연비차액
					$this->commute_oil_fee = $row ['29']; // 출퇴근유류비
					$this->instl_fee = $row ['30']; // 차량할부
					$this->instl_deg = $row ['31']; // 할부회차
					$this->deposit = $row ['32']; // 예치금
					$this->ada_pay = $row ['33']; // 선지급
					$this->account_fee = $row ['34']; // 기장료
					$this->trans_fee = $row ['35']; // 이체수수료
					$this->paint_exp = $row ['36']; // 도색비
					$this->charoff_etc_fee = $row ['37']; // 기타
					$this->incm_tax = $row ['38']; // 사업소득세
					$this->attend_cnt = $row ['39']; // 출근일수
					$this->dayoff_cnt = $row ['40']; // 결근일수
					$this->sply_yn = $row ['41'];
					$this->notice =  $row ['42'];
					$this->sply_dt =  $row ['43'];
					*/
					
					$this->mem_id       = $row['0'];
					$this->name         = $row['1'];
					$this->car_id       = $row['2'];
					$this->gubun_tp     = $row['3'];
					$this->car_no       = $row['4'];
					$this->cusm_cd      = $row['5'];
					$this->c_brno       = $row['6'];
					$this->soyu_tp      = $row['7'];
					$this->sply_dt = $row['8'];
					$this->bank_nm      = $row['9'];
					$this->act_nm       = $row['10'];
					$this->actno        = $row['11'];
					$this->closing_date      = $row['12'];
					$this->sply_amt     = $row['13'];
					$this->fare_amt     = $row['14'];
					
					if($this->gubun_tp == '1') {
						$this->comm_exp        = $row['15'];      
						$this->car_wash_exp    = $row['16'];      
						$this->attend_exp      = $row['17'];      
						$this->incen_pay       = $row['18'];      
						$this->dil_van_exp     = $row['19'];      
						$this->apd_dil_exp     = $row['20'];      
						$this->dil_etc_exp     = $row['21'];      
						$this->receipt_exp     = $row['22'];      
						$this->early_slot      = $row['23'];      
						$this->per_incen_pay   = $row['24'];          
						$this->mngt_exp        = $row['25'];      
						$this->surtax          = $row['26'];      
						$this->insu_fee        = $row['27'];      
						$this->insu_deg        = $row['28'];      
						$this->commit_fee      = $row['29'];      
						$this->car_tax         = $row['30'];      
						$this->gps_fee         = $row['31'];      
						$this->fine_fee        = $row['32'];
						$this->acct_fee        = $row['33'];      
						$this->mileage_fee     = $row['34'];
						$this->commute_oil_fee = $row['35'];      
						$this->instl_fee       = $row['36'];      
						$this->instl_deg       = $row['37'];      
						$this->deposit         = $row['38'];      
						$this->ada_pay         = $row['39'];      
						$this->account_fee     = $row['40'];      
						$this->trans_fee       = $row['41'];      
						$this->paint_exp       = $row['42'];      
						$this->charoff_etc_fee = $row['43'];       
						$this->incm_tax        = $row['44'];   
						$this->tot_dil_amt     = $row['50'];
						$this->tot_dedt_amt    = $row['51'];
					}
					else if ($this->gubun_tp == '2') {
						$this->oil_exp         = $row['15'];
						$this->dayoff_dedt     = $row['16'];
						$this->ex_incen_pay    = $row['17'];
						$this->apd_dil_exp     = $row['18'];
						$this->dil_etc_exp     = $row['19'];
						$this->receipt_exp     = $row['20'];
						$this->mngt_exp        = $row['21'];
						$this->surtax          = $row['22'];
						$this->insu_fee        = $row['23'];
						$this->insu_deg        = $row['24'];
						$this->commit_fee      = $row['25'];
						$this->car_tax         = $row['26'];
						$this->fine_fee        = $row['27'];
						$this->acct_fee        = $row['28'];
						$this->mileage_fee     = $row['29'];
						$this->commute_oil_fee = $row['30'];
						$this->instl_fee       = $row['31'];
						$this->instl_deg       = $row['32'];
						$this->deposit         = $row['33'];
						$this->ada_pay         = $row['34'];
						$this->account_fee     = $row['35'];
						$this->trans_fee       = $row['36'];
						$this->paint_exp       = $row['37'];
						$this->charoff_etc_fee = $row['38'];
						$this->incm_tax        = $row['39'];
						$this->tot_dil_amt     = $row['43'];
						$this->tot_dedt_amt    = $row['44'];
					}
					else {
						$this->extension_pay          = $row['15'];
						$this->annual_pay             = $row['16'];
						$this->early_slot             = $row['17'];
						$this->dispatcher_amt         = $row['18'];
						$this->commit_pay             = $row['19'];
						$this->meal_pay               = $row['20'];
						$this->car_assist_amt         = $row['21'];
						$this->etc_pay                = $row['22'];
						$this->etc_amt                = $row['23'];
						$this->pension_fee            = $row['24'];
						$this->insurance_fee          = $row['25'];
						$this->recuperation_fee       = $row['26'];
						$this->unemploy_insurance_fee = $row['27'];
						$this->income_tax             = $row['28'];
						$this->city_tax               = $row['29'];
						$this->prepay_amt             = $row['30'];
						$this->etc_deduct_amt         = $row['31'];
						$this->attend_deduct_amt      = $row['32'];
						$this->tot_dil_amt            = $row['36'];
						$this->tot_dedt_amt           = $row['37'];
					}
				}
				$rs->free ();
			}
		}
	}
	public function createMonthlyReport($type,$mem_id,$search_dt) {
		$sql = "CALL ".self::CONST_DB.".auto_month_pay('" . $type . "','" . $mem_id . "','" . $search_dt . "');select @out_err_cd, @out_err_msg;";
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}
	public function modifyMonthlyReport(  $proc_tp , $sply_dt              , $mem_id       , $account_fee  , $acct_fee       , $ada_pay       , $apd_dil_exp
										, $attend_exp            , $car_tax      , $car_wash_exp , $charoff_etc_fee, $comm_exp      , $commit_fee
										, $commute_oil_fee       , $dayoff_dedt  , $deposit      , $dil_etc_exp    , $dil_van_exp   , $early_slot
										, $ex_incen_pay          , $fare_amt     , $fine_fee     , $gps_fee        , $incen_pay     , $incm_tax
										, $instl_deg             , $instl_fee    , $insu_deg     , $insu_fee       , $mileage_fee   , $mngt_exp
										, $oil_exp               , $paint_exp    , $per_incen_pay, $receipt_exp    , $sply_amt      , $surtax
										, $trans_fee             , $extension_pay, $annual_pay   , $dispatcher_amt , $commit_pay    , $meal_pay
										, $car_assist_amt        , $etc_pay      , $etc_amt      , $pension_fee    , $insurance_fee , $recuperation_fee
										, $unemploy_insurance_fee, $income_tax   , $city_tax     , $prepay_amt     , $etc_deduct_amt, $attend_deduct_amt
										, $month_notice, $total_sply_amt, $fare_val, $ded_val ) {
		
		/*
		 * $sql = "call devdog.pay_clac_modify('" . $proc_tp . "','" . $mem_id . "','" . $sply_amt . "','" . $fare_amt . "','" . $comm_exp . "','" . $car_wash_exp . "' ,'" . $attend_exp . "','" . $incen_pay . "','" . $dil_van_exp . "','" . $apd_dil_exp . "','" . $dil_etc_exp . "','" . $mngt_exp . "' ,'" . $surtax . "','" . $insu_fee . "','" . $insu_deg . "','" . $commit_fee . "','" . $car_tax . "','" . $gps_fee . "','" . $fine_fee . "' ,'" . $acct_fee . "','" . $mileage_fee . "','" . $commute_oil_fee . "','" . $instl_fee . "','" . $instl_deg . "','" . $deposit . "' ,'" . $ada_pay . "','" . $account_fee . "','" . $trans_fee . "','" . $paint_exp . "','" . $charoff_etc_fee . "','" . $incm_tax . "');select @out_err_cd, @out_err_msg;";
		 */
		$sql = "CALL ".self::CONST_DB.".pay_clac_modify('" . $proc_tp                . "','" . $sply_dt        . "','" . $mem_id        . "','" . $account_fee   . "','" . $acct_fee        . "','" . $ada_pay        . "','" . $apd_dil_exp
												   . "','" . $attend_exp             . "','" . $car_tax       . "','" . $car_wash_exp  . "','" . $charoff_etc_fee . "','" . $comm_exp       . "','" . $commit_fee
												   . "','" . $commute_oil_fee        . "','" . $dayoff_dedt   . "','" . $deposit       . "','" . $dil_etc_exp     . "','" . $dil_van_exp    . "','" . $early_slot
												   . "','" . $ex_incen_pay           . "','" . $fare_amt      . "','" . $fine_fee      . "','" . $gps_fee         . "','" . $incen_pay      . "','" . $incm_tax
												   . "','" . $instl_deg              . "','" . $instl_fee     . "','" . $insu_deg      . "','" . $insu_fee        . "','" . $mileage_fee    . "','" . $mngt_exp
											       . "','" . $oil_exp                . "','" . $paint_exp     . "','" . $per_incen_pay . "','" . $receipt_exp     . "','" . $sply_amt       . "','" . $surtax
												   . "','" . $trans_fee              . "','" . $extension_pay . "','" . $annual_pay    . "','" . $dispatcher_amt  . "','" . $commit_pay     . "','" . $meal_pay
												   . "','" . $car_assist_amt         . "','" . $etc_pay       . "','" . $etc_amt       . "','" . $pension_fee     . "','" . $insurance_fee  . "','" . $recuperation_fee
												   . "','" . $unemploy_insurance_fee . "','" . $income_tax    . "','" . $city_tax      . "','" . $prepay_amt      . "','" . $etc_deduct_amt . "','" . $attend_deduct_amt
                                                   . "','" . $month_notice . "','" . $total_sply_amt . "','" . $fare_val . "','" . $ded_val . "');select @out_err_cd, @out_err_msg;";
		 echo "------".$sql;
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}
}



